package org.example.demo21.iterator.impl;

import org.example.demo21.iterator.DrinkIterator;
import org.example.demo21.iterator.DrinkMenu;
import org.example.demo21.iterator.entity.MenuItem;
import org.example.demo21.iterator.iter.DrinkShopIter;
import org.springframework.stereotype.Component;


/**
 *
 * @author guocong
 * @since 2024/4/1 14:01
 */
@Component
public class DrinkShopMenu implements DrinkMenu {

    static final int MAX_ITEMS = 5;
    MenuItem[] menuItems;
    int numberOfItems = 0;

    public DrinkShopMenu() {
        menuItems = new MenuItem[MAX_ITEMS];
        addItem(1, "库迪咖啡", "便宜又好喝。。。");
        addItem(2, "瑞幸咖啡", "薅不到九块九的羊毛，就贼特么贵。。。");
        addItem(3, "幸运咖", "经济实惠，但好喝的就那么几个。。。");
        addItem(4, "星巴克", "怪贵的，还没感觉多好喝。。。");
        addItem(5, "雀巢", "我速溶啊大哥。。。");
    }

    @Override
    public void addItem(int code, String name, String description) {
        MenuItem drinkShopItem = new MenuItem(name, description, code);
        //判断数组是否越界
        if (numberOfItems > MAX_ITEMS) {
            System.out.println("不好意思，菜单满了....");
        } else {
            menuItems[numberOfItems] = drinkShopItem;
            numberOfItems++;
        }
    }

    @Override
    public DrinkIterator createIter() {
        return new DrinkShopIter(menuItems);
    }

}
